- drawing of three dimensional surfaces in Xi -
The drawing of surfaces in the three dimensional space is similar to the drawing of contour plots in the plane. We begin this example as the previous. First open a 3d graphic device with enough bits per pixel:
( 1)>window(0,\bpp=3,\t3d);Say we want to plot the surface of the function 'sin(x)*cos(y)' which was already presented in the contour plot example. Like there we have to subdivide the square (-5,-5) to (5,5) into enough pieces. Again we make use of the interval2d library function:
( 2)>[x,y]=interval2d(-5,-5,5,5,30,30); Function interval2d definedThe square is now divided into 30x30 equally spaced tiles and we are able to calculate the z coordinates:
( 3)>z=sin(x)*cos(y);Now plot the surface using the surface3d function which is functionally similar to the contour function. We want to lay a white grid over the surface with the patches colored green:
( 4)>surface3d(z,\color=3,\gridColor=1);Then turn the plot in same way as in the previous example and put titles to the axes. Change the zrange to smooth the plot a little:
( 4)>plot3d(\angle={60,30,-90},\xtitle="x",\ytitle="y",\zrange={-2,2});The surface is now only displayed as a simple wireframe plot and you may ask, why we've defined a patch color in line 4 when there are actually no patches are drawn. This is a good point point out the two different ideas behind the 2d and 3d graphic device.
The 2d graphic device ist mostly based on WYSIWYG (What You See Is What You Get). If you build a 2d plot in the X device and don't change the aspect ratio afterwards the plots on all other devices should be the same (if not you have found a bug). The 3d graphic device is based on a completly different philosophy: What you see is the best the graphic device can do (WYSITBTGDCD?). This is necessary because there are lots of possible 3d graphic devices. At the moment only X and povraydevices are worked out but principally every raytracer oder renderer can be supported. Actually Bodo is thinking about a PEX- Device) which may lead to different results. Furthermore a WireFrame-Device is much faster than povray and is clearly the best choice when positioning and turning the plots.
After you have positioned the plot as you like, you may think about the visualization. At the moment Xi has a buildin HiddenLine and ConstantShading device, a GouraudShading device may be implemented in some future version. If you want to switch to hidden lines, you simply have to change the device:
( 5)>window(0,\HiddenLine);or for constant shading:
( 6)>window(0,\ConstShade);It should be obvious now why we've defined the color of the patches.
As in the previous example we want to make a povray picture of this situation again. The process is straight forward:
( 7)>window(1,\bpp=3,\t3d,\pov); ( 8)>surface3d(z,\color=4,\gridColor=1); ( 9)>plot3d(\angle={60,30,-90},\xtitle="x",\ytitle="y",\zrange={-2,2}); ( 10)>window(1,\close); ( 11)>$ povray +ixigraph.pov -oxigraph.tga +w900 +h800 -d +ft ( 12)>w=read_targa("xigraph.tga") ( 13)>d=crop(w); ( 14)>write_gif("xigraph.gif,color_reduce(d,\colors=255));The result (after crop) looks like:
Now 'play' a little bit. Let's begin a new Xi session and open a 3d graphic device:
( 1)>window(0,\bpp=3,\t3d);Plot the full helix given by the following formular
x(r,t) = r*sin(t) y(r,t) = r*cos(t) z(r,t) = tAgain use the interval2d function to tile the (r,t)-plane and calculate the x,y,z coordinates on this tiling.
( 2)>[r,t]=interval2d(0,0,1,2*~pi,30,30); Function interval2d defined ( 3)>x=r*sin(t); y=r*cos(t); z=t;Since the helix is a little more complicated, we have to set the x and y coordinates in the surface3d function explicitly. Choose the same colors and rotation as above:
( 4)>surface3d(z,x,y,\color=3,\gridColor=1); ( 5)>plot3d(\angle={60,30,-90},\xtitle="x",\ytitle="y");Then switch to the ConstantShading device:
( 6)>window(0,\ConstShade);Now for another povray picture:
( 7)>window(1,\bpp=3,\t3d,\pov); ( 8)>surface3d(z,x,y,\color=3,\gridColor=1); ( 9)>plot3d(\angle={60,30,-90},\xtitle="x",\ytitle="y"); ( 10)>window(1,\close); ( 11)>$ povray +ixigraph.pov -oxigraph.tga +w700 +h700 -d +ft
The result (after crob) ahould look like this: